package com.fms.controllers.form9;

import com.fms.model.Form9;
import com.fms.dao.Form9DAO;
import java.awt.List;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.validation.IFormValidator;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;

public class Payroll extends WebPage{
	
	private Model payroll_idModel = new Model();
	private Model org_idModel = new Model();
	private Model dateModel = new Model();
	private Model activityModel = new Model();
	private Model purposeModel = new Model();
	private Model disbursed_byModel = new Model();
	private Model approved_byModel = new Model();
	private Model date_createdModel = new Model();
	private Model uploaderModel = new Model();
	private Model statusModel = new Model();
	
	public Payroll(){
		
		Form payrollForm = new Form ("payrollForm");
		
		TextField payroll_id = new TextField("payroll_id", payroll_idModel);
		payroll_id.setRequired(true);
		payrollForm.add(payroll_id);
		
		TextField org_id = new TextField("org_id", org_idModel);
		org_id.setRequired(true);
		payrollForm.add(org_id);
		
		TextField date = new TextField("date", dateModel);
		date.setRequired(true);
		payrollForm.add(date);
		
		TextField activity = new TextField("activity",activityModel);
		activity.setRequired(true);
		payrollForm.add(activity);
		
		TextField purpose = new TextField("purpose", purposeModel);
		purpose.setRequired(true);
		payrollForm.add(purpose);
		
		TextField disbursed_by = new TextField("disbursed_by", disbursed_byModel);
		disbursed_by.setRequired(true);
		payrollForm.add(disbursed_by);
		
		TextField approved_by = new TextField("approved_by", approved_byModel);
		approved_by.setRequired(true);
		payrollForm.add(approved_by);
		
		TextField date_created = new TextField("date_created", date_createdModel);
		date_created.setRequired(true);
		payrollForm.add(date_created);
		
		TextField uploader = new TextField("uploader", uploaderModel);
		uploader.setRequired(true);
		payrollForm.add(uploader);
		
		TextField status = new TextField("status", statusModel);
		status.setRequired(true);
		payrollForm.add(status);
		
		add(payrollForm);
		
		Button payrollAdd = new Button ("payrollAdd"){
			
			public void onSubmit(){
				
				String npayroll_id = (String)payroll_idModel.getObject();
				String norg_id = (String)org_idModel.getObject();
				String date = (String)dateModel.getObject();
				String activity = (String)activityModel.getObject();
				String purpose = (String)purposeModel.getObject();
				String disbursed_by = (String)disbursed_byModel.getObject();
				String approved_by = (String)approved_byModel.getObject();
				String date_created = (String)date_createdModel.getObject();
				String uploader = (String)uploaderModel.getObject();
				String status = (String)statusModel.getObject();
				
				int payroll_id = Integer.parseInt(npayroll_id);
				int org_id = Integer.parseInt(norg_id);
				
				Form9 form9 = new Form9(payroll_id, org_id, date, activity, purpose,
						disbursed_by, approved_by, date_created, uploader, status);
				
				Form9DAO f9DAO = new Form9DAO();
				f9DAO.insert(form9);
				
			}
		};
		
	}

}
